<!-- 
All rights Reserved, Designed By www.youyacao.com 
@Description:视频列表
@author:成都市一颗优雅草科技有限公司     
@version 松鼠聚合直播系统v2.0
注意：本前端源码遵循 MulanPSL-2.0开源协议（木兰宽松许可证）本内容仅限于个人参考，禁止用于其他的商业用途
需要商业用途或者定制开发等可访问songshu.youyacao.com   联系QQ:422108995 23625059584

 -->


<template>
    <div>
        <van-search
                v-model="keyword"
                placeholder="请输入搜索关键词"
                show-action
                shape="round"
                @search="onSearch"
        >
            <div slot="action" @click="onSearch">搜索</div>
        </van-search>
        <div style="padding:10px 20px; background: #ffffff;">
            <van-button size="large" round  type="primary" icon="plus" style="height: 40px; line-height: 40px;" to="/editvideo">添加小视频</van-button>
        </div>
        <van-card
                v-for="item in list.data"
        >
            <div slot="thumb">
                <van-image
                        fit="cover"
                        width="80px"
                        height="80px"
                        :src="item.img"
                />
            </div>
            <div slot="title" style="font-weight: bold;">{{item.title}}</div>
            <div slot="num" style="padding: 10px;">收藏次数：{{item.collect_times}}次</div>
            <div slot="desc" style="color: #7d7e80;">
                <div style="padding-top: 20px;">发布时间：{{item.create_time}}</div>
                <div style="padding: 10px 0px;">更新时间：{{item.update_time}}</div>
            </div>
            <div slot="footer">
                <van-button size="mini" type="danger" @click="deleteVideo(item.id)">删除</van-button>
                <van-button size="mini" type="info" :to="'/editvideo?id='+item.id">修改</van-button>
            </div>
        </van-card>
        <van-pagination
                v-model="list.current_page"
                :total-items="list.total"
                :items-per-page="list.per_page"
                @change="changePage"
                v-if="list.last_page>1"
        />
    </div>
</template>

<script>
    import global_ from '../Global';
    import { Notify } from 'vant';
    import { Dialog } from 'vant';
    import { Toast } from 'vant';
    export default {
        name: "video",
        data(){
            return {
                keyword:"",
                list:{}
            }
        },
        created(){
            this.loadInfo(1);
        },
        methods:{
            onSearch:function () {
                this.loadInfo(1);
            },
            loadInfo:function (page) {
                this.$axios.get(global_.serverUrl+"admin/video/getlist",{
                    params:{
                        keyword:this.keyword,
                        page:page
                    }
                }).then((res)=>{
                    if(res.code == 1){
                        this.list = res.data;
                    }else{
                        Notify("列表加载失败");
                    }
                });
            },
            changePage:function (page) {
                this.loadInfo(page);
            },
            deleteVideo:function (id) {
                Dialog.confirm({
                    title: '提示',
                    message: '删除后不可恢复，确认删除此视频？'
                }).then(() => {
                    this.$axios.get(global_.serverUrl+"admin/video/delete",{
                        params:{
                            id:id
                        }
                    }).then((res)=>{
                        if(res.code == 1){
                            this.loadInfo(this.list.current_page);
                            Notify({ type: 'success', message: '删除成功' });
                        }else{
                            Toast(res.msg);
                        }
                    })
                }).catch(() => {
                    // on cancel
                });
            }
        }
    }
</script>

<style scoped>

</style>
